package com.alatus.manager;

import com.alatus.mapper.TPermissionMapper;
import com.alatus.mapper.TRoleMapper;
import com.alatus.model.TPermission;
import com.alatus.model.TRole;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class UserManager {
    //    注入角色的Mapper
    @Resource
    private TRoleMapper tRoleMapper;
    @Resource
    private TPermissionMapper tPermissionMapper;

    public List<String> loadRoleListByUser(Integer id){
//        查询一下当前登录的角色
        List<TRole> tRoleList = tRoleMapper.selectByUserId(id);
        List<String> roleList = new ArrayList<>();
        tRoleList.forEach(tRole -> {
            roleList.add(tRole.getRole());
        });
        return roleList;
    }
    public List<TPermission> getMenuPermissionList(Integer id){
        List<TPermission> menuPermissionList = tPermissionMapper.selectMenuPermissionByUserId(id);
        return menuPermissionList;
    }

    public List<TPermission> selectButtonPermissionByUserId(Integer id){
        List<TPermission> buttonPermissionByUserId = tPermissionMapper.selectButtonPermissionByUserId(id);
        return buttonPermissionByUserId;
    }
}
